<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Controller;

use App\Service\UserService;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\Di\Annotation\Inject;

/**
 * @Controller()
 */

class IndexController extends AbstractController
{
    /**
     * @Inject()
     * @var UserService
     */
    protected $userService;

    /*public function __construct(UserService $userService)
    {
        $this->userService = $userService;
    }*/

    public function index()
    {
        $user = $this->request->input('user', 'Hyperf');
        $method = $this->request->getMethod();

        return [
            'method' => $method,
            'message' => "Hello {$user}.",
        ];
    }

    public function get()
    {
        return [
            'message' => '欢迎进入get'
        ];
    }

    /**
     * @RequestMapping(path="view", method="get,post")
     */
    public function view(RequestInterface $request):array
    {
        $id = $request->input('id', 1);
        $info = $this->userService->getInfoById((int)$id);
        return $info;
    }
}
